package com.greenhouse.protocol.coder;

import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;

/**
 * ByteBufToWebSocketFrameEncoder
 *
 * @author lxr
 * @create 2017-11-20 13:46
 **/
public class ByteBufToWebSocketFrameEncoder extends MessageToMessageEncoder<ByteBuf> {

	@Override
	protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> out)
			throws Exception {
		if (byteBuf == null) {
			return;
		}
		BinaryWebSocketFrame result = new BinaryWebSocketFrame();
		result.content().writeBytes(byteBuf);
		out.add(result);
	}
}
